package com.itic.ht.cms.questype.service;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.itic.appbase.framework.common.basevo.User;
import com.itic.appbase.framework.common.constants.DBConst;
import com.itic.appbase.framework.common.constants.IticConst;
import com.itic.appbase.framework.common.service.CrudService;
import com.itic.appbase.framework.utils.IdGen;
import com.itic.ht.cms.questype.persistence.dao.QuestionTypeDao;
import com.itic.ht.cms.questype.persistence.model.QuestionType;
import com.itic.ht.cms.questype.persistence.model.QuestionTypeExample;


@Service
@Transactional
public class QuestionTypeService extends CrudService<QuestionTypeDao,QuestionType,QuestionTypeExample> {
    @Autowired
    private QuestionTypeDao questionTypeDao;

    //批量导入业务
	public String imp(HttpServletRequest request,List<QuestionType> dataList) {
		if(dataList.size()>0){
			Date date = new Date();
			User user = (User)request.getSession().getAttribute(IticConst.PS_SESSION_USERINFO_KEY);
			
			for(QuestionType temp:dataList){
				temp.setId(IdGen.uuid());
				temp.setCreateTime(date);
				temp.setUpdateTime(date);
				temp.setIsEffective(DBConst.TRUE);
				
				temp.setOrgCode(user.getOrg());
				temp.setCreateUser(user.getId());
				questionTypeDao.insert(temp);
			}
		}
		return "success";
	}
	
	//批量导入业务
	public QuestionType getModelByTypeCode(String typeCode) {
		
		QuestionType questionType = null;
		QuestionTypeExample example = new QuestionTypeExample();
		example.createCriteria().andIsEffectiveEqualTo(DBConst.TRUE).andTypeCodeEqualTo(typeCode);
        List<QuestionType> list = this.list(example);
        
        if(list!=null && list.size()>0){
        	questionType = list.get(0);
        }
		return questionType;
	}
	
	public QuestionType getTypeName(String id){
		return questionTypeDao.selectByPrimaryKey(id);
	}

}